package com.elephantgreen.xml;

import java.util.Vector;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.elephantgreen.common.ElephantgreenCommon;
import com.elephantgreen.common.Products;
import com.elephantgreen.util.Util;



public class ProductsXml extends ElephantgreenXmlHandler {

	/**
	 * @param fName
	 * @param parentNodeName
	 */
	public ProductsXml(String fName, String parentNodeName) {
		super(fName, parentNodeName);

	}

	/* (non-Javadoc)
	 * @see com.elephantgreen.persistance.ElephantgreenXmlHandler#getItems()
	 */
	@Override
	public Vector<ElephantgreenCommon> getItems() {


		Vector<ElephantgreenCommon> vProducts = new Vector<ElephantgreenCommon>();

		for (int temp = 0; temp < getNodes().getLength(); temp++) {

			Node nNode = getNodes().item(temp);
			if (nNode.getNodeType() == Node.ELEMENT_NODE) {

				Element element = (Element) nNode;
				
				Products prd = new Products(
						Util.getTagValue("productCode", element),
						Util.getTagValue("productSubCode", element), 
						Util.getTagValue("productName", element),
						Util.getTagValue("bottleSize", element), 
						Util.getTagValue("bottleType", element), 
						Util.getTagValue("purchasePrice", element),
						Util.getTagValue("salePrice", element),
						Util.getTagValue("marketPrice", element),
						Util.getTagValue("reorderLevel", element), 
						Util.getTagValue("bottlesPerCase", element),
						Util.getTagValue("crate", element), 
						Util.getTagValue("cratePrice", element), 
						Util.getTagValue("crateGroup", element), 
						Util.getTagValue("empty", element), 
						Util.getTagValue("emptyPrice", element), 
						Util.getTagValue("emptyGroup", element), 
						Util.getTagValue("comments", element), 
						Util.getTagValue("active", element));

				vProducts.add(prd);

			}
		}
		return vProducts;
	}

}
